package cn.school.controller.hotel;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.hotel.entity.TripLabelDic;
import cn.school.hotel.service.TripLabelService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hotel/label")
public class TripLabelDicController {


    @Autowired
    private TripLabelService tripLabelService;

    @ApiOperation("list => 分页酒店服务标签列表")
    @GetMapping(value = "/getLabelList")
    public CommonResult<CommonPage<TripLabelDic>> getLabelList(TripLabelDic tripComment,
                                                                  @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        IPage<TripLabelDic> pageList = tripLabelService.getLabelList(tripComment,pageSize,pageNum);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @ApiOperation("list => 酒店服务标签列表")
    @GetMapping(value = "/getLabelListByParentId")
    public CommonResult<List<TripLabelDic>> getLabelListByParentId(TripLabelDic tripComment) {
        List<TripLabelDic> pageList = tripLabelService.getLabelListByParentId(tripComment);
        return CommonResult.success(pageList);
    }

    @ApiOperation("list => 创建酒店服务标签列表")
    @PostMapping(value = "/createOrUpdateLabelDic")
    public CommonResult<List<TripLabelDic>> createOrUpdateLabelDic(@RequestBody TripLabelDic tripComment) {
        int count = tripLabelService.createOrUpdateLabelDic(tripComment);
        if(count>0){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }

    }

    @ApiOperation("list => 创建酒店服务标签列表")
    @GetMapping(value = "/deleteLabelDic")
    public CommonResult<Integer> createOrUpdateLabelDic(@Param("id")String id) {
        Integer count = tripLabelService.deleteLabelDicById(id);
        if(count>0){
            return CommonResult.success();
        }else{
            return CommonResult.failed();
        }
    }

}
